# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/4/9 19:22
# @Author   : Robot-Zsj
"""
description:

input
10
1 2 1 2 1 2 1 2 1 2
5

output
2
1
2
"""

n = int(input())
seqs = list(map(int, input().split()))
threshold = int(input())

cnts = {}

for num in seqs:
    cnts.setdefault(num, 0)
    cnts[num] += 1

items = list(filter(lambda x: x[1] >= threshold, cnts.items()))

print(len(items))

if len(items) > 0:
    items.sort(key=lambda x: (-x[1], x[0]))
    for num, _ in items:
        print(num)
